package app.r_teenus.frontend.controller;


import org.springframework.binding.message.MessageBuilder;
import org.springframework.binding.message.MessageContext;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import app.r_teenus.backend.model.Address;


@Component
public class AddressValidator {

    /**
     * Spring Web Flow activated validation (validate + ${state}).
     * Validates 'personForm' view state after binding to person.
     */
    public void validateAddressForm(Address address, MessageContext context) {
        if (!StringUtils.hasText(address.getCountry())) {
            context.addMessage(new MessageBuilder().error().source("country").code("address.form.country.error").build());
        }
        if (!StringUtils.hasText(address.getZipCode())) {
            context.addMessage(new MessageBuilder().error().source("zipCode").code("address.form.zipPostal.error").build());
        }
    }
}
